package com.example.waterorder.controller;

import com.example.waterorder.entity.Worker;
import com.example.waterorder.service.UserService;
import com.example.waterorder.tools.Result;
import com.example.waterorder.entity.constant.WaterMessage;
import com.example.waterorder.service.WorkerService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/worker")
public class WorkerController {
    @Resource
    private WorkerService workerService;

    @GetMapping("/select")
    @Operation(summary = "通过送水员id查询送水员信息")
    public Result selectById(@RequestParam("workerId") String workerId){
        Worker worker = workerService.selectById(workerId);
        return worker!=null?new Result(true,worker)
                :new Result(false);
    }

    @PostMapping("/register")
    @Operation(summary = "送水员注册,返回消息提示")
    public Result register(@RequestBody Worker worker){
        Integer flag = workerService.register(worker);
        if (flag==1)
        {

        }
        return flag==1?new Result(true, WaterMessage.REGISTER_SUCCESS)
                :new Result(false,WaterMessage.REGISTER_FAILD);
    }

    @PutMapping("/update")
    @Operation(summary = "送水员更改个人信息")
    public Result updateWorker(@RequestBody Worker worker){
        Integer flag = workerService.updateWorker(worker);
        return flag==1?new Result(true, WaterMessage.UPDATE_SUCCESS)
                :new Result(false,WaterMessage.UPDATE_FAILD);
    }
}
